package cn.edu.hqu.cst.android.activitylifecycle;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class SingleTopActivity extends AppCompatActivity implements View.OnClickListener {
    static int cntActivity=1;
    Button btnCreateActivity;
    TextView tvCntActivity;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_single_top);
        btnCreateActivity=findViewById(R.id.btn_singleTop_activity_create_activity);
        tvCntActivity=findViewById(R.id.tv_singleTop_activity_cnt_activity);
        btnCreateActivity.setOnClickListener(this);
        tvCntActivity.setText(getText(R.string.cntActivity)+String.valueOf(cntActivity));
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        if(cntActivity>=1)
            cntActivity--;
    }
    @Override
    public void onClick(View v) {
        Intent intent=new Intent(this,SingleTopActivity.class);
        cntActivity++;
        startActivity(intent);
    }
}


